//
//  UIView+properties.m
//  KSBridgeDesign
//
//  Created by huzhaoke on 2021/4/5.
//

#import "UIView+properties.h"

@implementation UIView (properties)

- (void)setLeft:(CGFloat)left
{
    CGRect frame = self.frame;
    frame.origin.x = left;
    self.frame = frame;
}

- (CGFloat)left
{
    return CGRectGetMinX(self.frame);
}

- (void)setTop:(CGFloat)top
{
    CGRect frame = self.frame;
    frame.origin.y = top;
    self.frame = frame;
}

- (CGFloat)top
{
    return CGRectGetMinY(self.frame);
}

- (CGFloat)bottom
{
    return CGRectGetMaxY(self.frame);
}

- (void)setBottom:(CGFloat)bottom
{
    self.top = bottom - self.height;
}

- (CGFloat)right
{
    return CGRectGetMaxX(self.frame);
}

- (void)setRight:(CGFloat)right
{
    self.left = right - self.width;
}

- (void)setCenterX:(CGFloat)centerX
{
    CGPoint center = self.center;
    center.x = centerX;
    self.center = center;
}

- (CGFloat)centerX
{
    return self.center.x;
}

- (void)setCenterY:(CGFloat)centerY
{
    CGPoint center = self.center;
    center.y = centerY;
    self.center = center;
}

- (CGFloat)centerY
{
    return self.center.y;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (CGFloat)width
{
    return CGRectGetWidth(self.frame);
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

- (CGSize)size
{
    return self.frame.size;
}

- (void)setOrigin:(CGPoint)origin
{
    self.frame = (CGRect){.size=self.frame.size,.origin=origin};
}

- (CGPoint)origin
{
    return self.frame.origin;
}

- (void) setOriginX:(CGFloat)originX centerY:(CGFloat)centerY
{
    self.origin = CGPointMake(originX, 0);
    self.center = CGPointMake(self.center.x, centerY);
}

- (void)setCenterX:(CGFloat)centerX originY:(CGFloat)originY
{
    self.origin = CGPointMake(0, originY);
    self.center = CGPointMake(centerX, self.center.y);
}

- (CGFloat)theHeightFromScreenBottom {
   CGRect rect = [self convertRect:self.bounds toView:[UIApplication sharedApplication].keyWindow];
    CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
   return screenH - rect.origin.y - rect.size.height;
}

@end
